package com.kun.demo03;

//由于多线程导致的并发问题，多个线程同时访问同一个资源时，可能会出现数据不一致的问题。
public class Thread_concurrencyProblem implements Runnable {
    private int count = 10;


    public void run() {
        while(true){
            if (count <= 0){
                return;
            }
            try {
                Thread.sleep(20);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "--> 获得第"+(count--)+"张票");
        }
    }

    public static void main(String[] args) {
        Thread_concurrencyProblem tickets = new Thread_concurrencyProblem();
        new Thread(tickets, "小张").start();
        new Thread(tickets, "小王").start();
        new Thread(tickets, "黄牛党").start();
    }


}
